home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c,comp.unix.programmer
- Path: howland.reston.ans.net!torn!sq!msb
- From: msb@sq.com (Mark Brader)
- Subject: Re: Q: '\n' character
- Message-ID: <1996Apr19.013148.18227@sq.com>
- Organization: SoftQuad Inc., Toronto, Canada
- References: <4kj66f$k0o@ren.cei.net> <829396473snz@genesis.demon.co.uk> <4kpd2g$eeb@masala.cc.uh.edu> <4l3ta3$c08@uhura.phoenix.net>
- Date: Fri, 19 Apr 1996 01:31:48 GMT
-
- > > ptr = strchr (buffer, '\n'); /* or strrchr() */
- > > if (ptr) *ptr = '\0';
- >
- > Which is a lot of code when this will do the same thing:
- > strtok( ptr, "\n");
-
- I think this was meant to be
-
- strtok( buffer, "\n");
-
- rather than introducing the new variable ptr which is needed in the first
- version. But anyway, it's wrong. If the FIRST character in the buffer is
- a newline, this strtok() call will say "I found no newline-delimited tokens"
- by returning a null pointer, and will leave the buffer alone.
-
- Therefore, if you try to use this to strip from the buffer the newline that
- fgets() left in it, you will end up with "\n" rather than "" in the buffer
- every time that a empty line was read from the input.
-
- --
- Mark Brader "You wake me up early in the morning to tell me I am
- msb@sq.com right? Please wait until I am wrong."
- SoftQuad Inc., Toronto -- John von Neumann, on being phoned at 10 a.m.
-
- My text in this article is in the public domain.
-